<?php
App::uses('CakeTime', 'Utility');
App::uses("Controller", "Controller");
class AppController extends Controller {
	var $title = "Welcom to";
	var $controllerName = "Quản lý";
	var $action_array = array(
			"index"			=> "Danh sách",
			"view"			=> "Chi tiết",
			"admin_index"	=> "Danh sách bản ghi",
			"admin_add"		=> "Thêm mới bản ghi",
			"admin_view"	=> "Chi tiết bản ghi",
			"admin_edit"	=> "Cập nhật bản ghi",
			//ACL
			"admin_user_permissions" => "Phân quyền người dùng",
			"admin_role_permissions" => "Phân quyền nhóm người dùng",
			"admin_synchronize" => "Đồng bộ",
			"admin_get_user_controller_permission" =>""
		);
	public $components = array(
		// "Comm",
		"Paginator",
		"Session",
		//"DebugKit.Toolbar",
		"Acl",
		"RequestHandler",
		"Security",
        "Auth" => array(
            "loginRedirect" => array("admin"=>true,"controller" => "users", "action" => "index"),
            "logoutRedirect" => array("controller" => "users", "action" => "login"),
			"authError" => "You must be logged in to view this page.",
			"loginError" => "Invalid Username or Password entered, please try again.",
			"authorize" => array(
                "Actions" => array("actionPath" => "controllers")
            )
        ));
	public $helpers = array("Session","Js","I18n.I18n");
	public function beforeFilter() {
		parent::beforeFilter();
		$this->Security->unlockedActions = array('home','add','check_out','access_price','received','get_people','change','delete','edit','del','book','booking','information','list_room','del_guest_book','find_room');
        if(isset($this->request->params["admin"]) && $this->request->params["admin"] == true){
			$this->layout = "admin";
        }

        //function
        $this->loadModel("Menu");
        $list_menus = $this->Menu->find("all");
        $this->set(compact("list_menus"));

        $this->set("title",$this->title);
        $tmpactionName = "";
        if(isset($this->action_array[$this->request->action])){
			$tmpactionName = $this->action_array[$this->request->action];
        }
        $this->set("actionName",$tmpactionName);
        $this->set("controllerName",$this->controllerName);
        $this->Auth->allow("admin_login","setup_price","check_out","unset_book","get_people","infomation","move_room","received","index","access_price","list_price","price","view","list_guest","home","list_room","del_guest_waiting","find_room","change","del","list_room_full");
        $this->Auth->allow('home','index','add','view','edit','listservice','countservice','delete','salary','format_price','salary_received','book','list_guest_cur','booking','information','del_guest_book','find_room');
    }
	public function isAuthorized($user) {
		//return false;
	}
	
	public function product_price($priceFloat) {
		$symbol = 'VNĐ';
		$symbol_thousand = '.';
		$decimal_place = 0;
		$price = number_format($priceFloat, $decimal_place, '', $symbol_thousand);
		return $price.$symbol;
		}

	// public function toggle($id,$stt,$s = "status"){

	// 	$this->layout = "ajax";
	// 	$this->autoRender = false;
	// 	//$this->request->onlyAllow("ajax");
 //        $model = $this->Comm->singularize($this->request->params["controller"]);
 //        if(isset($id)){
	// 		$this->loadModel($model);
 //            $this->$model->id = $id;
 //            $this->$model->saveField($s,$stt);
 //        }
 //        $this->render("ajax");
 //    }
}
